<template>
    <div class="page-container">
        <el-row style="margin: 10px 0" justify="space-between">
            <el-row>
                <el-row>
                    <el-form :model="search" :inline="true" size="small">
                        <el-form-item label="订单编号:" prop="id">
                            <el-input v-model="search.id" placeholder="请输入订单编号" ></el-input>
                        </el-form-item>
                        <el-form-item label="买家:" prop="nickname">
                            <el-input v-model="search.name" placeholder="请输入买家名称" ></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-date-picker
                                v-model="search.range"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                                size="small"
                                style="margin-left:10px;"
                                value-format="YYYY-MM-DD"
                            />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="getList">查询</el-button>
                            <el-button icon="ele-Refresh" @click="filterReset">重置</el-button>
                        </el-form-item>
                    </el-form>
                </el-row>
            </el-row>
        </el-row>
        <div class="list-container">
            <el-table :data="list" size="small" border style="width: 100%">
                <el-table-column prop="id" label="订单编号" width="180" />
                <el-table-column prop="nickname" label="买家" width="180" />
                <el-table-column prop="payAmount" label="订单金额" >
                    <template #default="scope">
                        <span style="color: red;">￥ {{ scope.row.payAmount?scope.row.payAmount:0 }} </span>
                    </template>
                </el-table-column>
                <el-table-column prop="twoSaleMoney" label="提成" >
                    <template #default="scope">
                        <span style="color: red;">￥ {{ scope.row.twoSaleMoney?scope.row.twoSaleMoney:0 }} </span>
                    </template>
                </el-table-column>            
                <el-table-column prop="createTime" label="下单时间" />
            </el-table>            
        </div>
        <div class="page-block">
            <el-pagination
                v-model:currentPage="search.current"
                v-model:page-size="search.size"
                :page-sizes="[10, 20, 30, 40]"
                :small="true"
                :disabled="false"
                :background="false"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :hide-on-single-page="true"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
        </div>
    </div>
</template>

<script>
import { reactive, toRefs, onMounted, computed, h } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import api from '/@/api/commonApi'


export default {
    name: 'Commission',
    setup(){
        const state = reactive({
            total: 0,
            list: [
                {id: '1', nickname: '张三', payAmount: 99, twoSaleMoney: 20, createTime: "2023-05-23 12:00:00"},
                {id: '2', nickname: '张三1', payAmount: 120, twoSaleMoney: 20, createTime: "2023-05-23 12:00:00"},
                {id: '3', nickname: '张三2', payAmount: 55, twoSaleMoney: 20, createTime: "2023-05-23 12:00:00"},
                {id: '4', nickname: '张三3', payAmount: 48, twoSaleMoney: 20, createTime: "2023-05-23 12:00:00"},
                {id: '5', nickname: '张三4', payAmount: 61, twoSaleMoney: 20, createTime: "2023-05-23 12:00:00"},
            ],
            search: {
                current: 1,
                size: 10
            }
        })

        // 获取数据
        const getList = () => {
            const search = JSON.parse(JSON.stringify(state.search))
            delete search.range
            // api.getSaleSeven({
            //     startTime: state.search.range ? state.search.range[0] : '',
            //     endTime: state.search.range ? state.search.range[1] : '',
            //     ...search
            // }).then(res => {
            //     console.log(res);
            // })
        }
        
        // 条数修改
        const handleSizeChange = e => {
            state.search.size = e
            getList()
        }
        // 页码修改
        const handleCurrentChange = e => {
            state.search.current = e
            getList()
        }
        // 重置
        const filterReset = () => {
            state.search = {
                current: 1,
                size: 10
            }
            getList()
        }
        
        onMounted(() => {
            getList()
        })
        return {
            ...toRefs(state),
            getList,
            filterReset,
            handleSizeChange,
            handleCurrentChange,
        }
    }
}
</script>

<style lang="scss" scoped>
.list-container{
    background: var(--next-color-white);
    :deep(.el-table__header-wrapper .el-table__cell) {
        background: var(--el-color-primary-light-9);
        color: var(--next-bg-menuBar-light-1);
    }
}
</style>